<?php
/**
*	接口文件
*	createname：雨中磐石
*	homeurl：http://www.rockoa.com/
*	Copyright (c) 2016 rainrock (www.rockoa.com)
*	Date:2016-01-01
*	explain：返回200为正常
*/

if(arrvalue($_GET,'laiyuan')=='web'){
	$origin = getheader('Origin');
	if(!isempt($origin) && !contain($origin, HOST)){
		header('Access-Control-Allow-Origin:*');
		header('Access-Control-Allow-Headers:X-Requested-With');
		header('Access-Control-Allow-Credentials:true');
		if(arrvalue($_SERVER,'REQUEST_METHOD')=='OPTIONS'){
			showreturn('ok');
		}
	}
}

class apiAction extends ActionNot
{
	public $logincheck  = true;
	public $agentrs;
	public $agentid		= 0;
	public $agentkey	= '';
	public $agentface;
	
	public function initAction()
	{
		$this->display	= false;
		if($this->logincheck){
			$agentkey = $this->get('agentkey');
			if(isempt($agentkey))$agentkey = $this->get('_w_yingkey');
			$mrs = m('agent')->getone("`agentkey`='$agentkey'");
			if(!$mrs)$this->showreturn('', 'agentkey not access', 199);
			$this->agentkey  = $agentkey;
			$this->agentrs   = $mrs;
			$this->agentid   = $mrs['id'];
			$this->agentface = getface($mrs['picurl']);
		}
		if($this->adminid>0)$this->getAdmininfo($this->adminid);
	}
	
	public function getvals($nae, $dev='')
	{
		$sv = $this->rock->jm->base64decode($this->post($nae));
		if($this->isempt($sv))$sv=$dev;
		return $sv;
	}
	
	public function getpostdata()
	{
		$postdata = '';
		if(isset($GLOBALS['HTTP_RAW_POST_DATA']))$postdata = $GLOBALS['HTTP_RAW_POST_DATA'];
		if($postdata=='')$postdata = trim(file_get_contents('php://input'));
		return $postdata;
	}
	
	/**
	*	获取cli上参数格式：-key=val
	*/
	public function getparams($key, $dev='')
	{
		if(PHP_SAPI != 'cli'){
			return $this->get($key, $dev);
		}
		return getparams($key, $dev);
	}
}